#ifndef _PRETTY_SIMPLE_ESI_OPTIONS_
#define _PRETTY_SIMPLE_ESI_OPTIONS_

#include <map>
#include <string>

namespace PESI {
  struct ltstr_cmp{
    bool operator()(const char* s1, const char* s2) const{ return strcmp(s1, s2) < 0; }
  };
  struct Options{
    Options(): _help(false),_verbose(false),_daemonize(false){}
    ~Options(){}

    bool parse( int argc, char **argv );
    void dump()const; // report args
    void usage( char **argv )const;
    bool verbose()const{ return _verbose; }
    bool help()const{ return _help; }
    bool daemonize()const{ return _daemonize; }

    bool hasOpt( const char *opt_name )const{
      return getOpt(opt_name) != NULL;
    }

    const char *operator[]( const char *opt_name )const{
      return this->getOpt(opt_name);
    }

    const char *getOpt( const char *opt_name )const{
      if( !strcmp( opt_name, "verbose" ) )
        return _verbose ? "yes" : "no";
      else if( !strcmp( opt_name, "help" ) )
        return _help ? "yes" : "no";
      else if( !strcmp( opt_name, "daemonize" ) )
        return _daemonize ? "yes" : "no";
      else{
        OptTable::const_iterator loc = _options.find( opt_name );
        if( _options.end() == loc ){ return NULL; }
        return loc->second.c_str();
      }
    }

  private:
    bool _verbose;
    bool _help;
    bool _daemonize;
    typedef std::map<const char*,std::string,ltstr_cmp> OptTable;
    OptTable _options;
  };
}
#endif
